"""
URL configuration for djangoProject project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
from sers.views import FamilyViewSet, CustomObtainTokenPairView, UserViewSet, schema_view
from rest_framework.documentation import include_docs_urls

# 1.注册路由
router = DefaultRouter()
router.register('myy/family', viewset=FamilyViewSet, basename='family')
router.register('user', viewset=UserViewSet, basename='user')

urlpatterns = [
    path("admin/", admin.site.urls),
    # path("family", views.FamilyViewSet.as_view({'get': 'list'}))
    path('login/', CustomObtainTokenPairView.as_view(), name='token_obtain_pair'),
    path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
    # API文档自动生成  方式1：coreapi
    path('docs/', include_docs_urls(title='T591接口文档')),
    # API文档swwager自动生成  方式2：drf-yasg  推荐 ：界面好看
    path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),  # 互动模式
    path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),  # 文档模式
]

# 2.把路由添加进主应用的urls
urlpatterns += router.urls
